class Solution {
public:
    string convert(string s, int numRows) {
		if (numRows == 1) return s;
		
		int sLen = s.length();
        vector<vector<char> > strMat(numRows, vector<char>(sLen, -1));
        
        bool isUp = false;
        int x = 0;
        int y = 0;
        for (int i=0; i<sLen; i++)
        {
            strMat[x][y] = s[i];
            
            if (isUp)
            {
                x -= 1;
                y += 1;
            }
            else
            {
                x += 1;
            }
            
            if (x == numRows - 1)   
                isUp = true;
            if (x == 0) 
                isUp = false;
        }
        
        string res = "";
        for (x=0; x<numRows; x++)
            for (y=0; y<sLen; y++)
                if (strMat[x][y] != -1)
                    res += strMat[x][y];

        return res;
    }
};